

/*
preferred habitat localization regressions:
alternative specification robustness: b2c proxy measure of demand shocks

output:
- f3d_*.pdf: localization figures

*/


* plotting options
set scheme lean_uncluttered

* command line option
* set to 1 to re-estimate PH regressions (slow)
if "`1'"=="" {
	local estimate_phregs 0
}
else {
	local estimate_phregs `1'
}



********************************************************************************
********************************************************************************
if `estimate_phregs' == 1 {

use ../data/phreg_clean_auction_notesbonds_govpx_shock_all.dta, clear

* merge b2c data
local b2c_vars b2c_all b2c_all_resid D_b2c_all ///
	b2c_indirectBidder b2c_indirectBidder_resid D_b2c_indirectBidder
merge m:1 cusip auctionDate using ///
	../data/auction_notesbonds_govpx_shock.dta, nogen keep(master match) ///
	keepusing(`b2c_vars')
sort close_time maturity_remaining cusip_govpx


* loop over b2c variables
* run alt PH regressions
foreach v of local b2c_vars {
	* change sign ofb2c to line up with yield shocks
	replace `v' = -`v'
	n di "running regressions: `v'"
	run_ph_alt_regression D_shock `v' , ///
		mat_var(maturity_remaining) ra_var(high_ra) long_var(term_long) ///
		security_id(cusip_govpx) auction_id(auction_id) ///
		mat_window(2) mat_long_window(4) mat_step(1) ///
		cluster_type("NT") bw(9) ///
		fname_stub("`v'")

}


}


********************************************************************************
********************************************************************************

* loop over b2c variables 
* plot
local b2c_vars b2c_all b2c_all_resid D_b2c_all ///
	b2c_indirectBidder b2c_indirectBidder_resid D_b2c_indirectBidder

foreach v of local b2c_vars {
	plot_ph_alt_regression, fname_stub("`v'") ///
		show_figs(0) figname("f3d_`v'") combine_figs(1) plot_pvals(0)
}



